package org.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.example.common.Result;
import org.example.pojo.Cart;
import org.example.service.CartService;
import org.example.mapper.CartMapper;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
* @author 13326
* @description 针对表【hards_cart】的数据库操作Service实现
* @createDate 2025-01-10 15:10:15
*/
@Service
public class CartServiceImpl extends ServiceImpl<CartMapper, Cart>
    implements CartService{
    @Resource
    private CartMapper cartMapper;
    @Override
    public Result add(Cart cart){
        int rows=cartMapper.insert(cart);
        return Result.ok("新增成功");
    }
    @Override
    public Result getall(Integer userId,Integer businessId){
        LambdaQueryWrapper<Cart> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Cart::getBusinessId,businessId);
        lambdaQueryWrapper.eq(Cart::getUserId,userId);
        List<Cart> list=cartMapper.selectall(userId,businessId);
//        for (int i = 0; i <= list.size(); i++) {
//
//        }
//        Long count=cartMapper.selectCount(lambdaQueryWrapper);
        HashMap<String,Object> map=new HashMap<>();
        map.put("list",list);
//        map.put("count",count);
        return Result.ok(map);

    }
    @Override
    public Result updatecart(Cart cart){
        int rows=cartMapper.updateById(cart);
        return Result.ok("修改成功");
    }
    @Override
    public Result clear(Integer userId,Integer businessId){
        int rows=cartMapper.deletecart(userId,businessId);
        return Result.ok("删除成功");

    }


}




